package com.person.jiaiplan.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.person.jiaiplan.pojo.R;
import com.person.jiaiplan.pojo.dto.AddSchedulePlanReqDTO;
import com.person.jiaiplan.pojo.entity.SchedulePlanLogs;
import com.person.jiaiplan.service.SchedulePlanLogsService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@RestController
@RequestMapping("scheduleplan")
@Validated
public class SchedulePlanController {

    @Autowired
    private SchedulePlanLogsService schedulePlanLogsService;

    @GetMapping("/query")
    public R<SchedulePlanLogs> queryByScheduleId(@RequestParam(name = "scheduleId") String scheduleId) {
        return R.ok(schedulePlanLogsService.getOne(Wrappers.lambdaQuery(SchedulePlanLogs.class).eq(SchedulePlanLogs::getScheduleId, scheduleId)));
    }

    @PostMapping("/add")
    public R<Boolean> addPlan(@Validated @RequestBody AddSchedulePlanReqDTO addSchedulePlanReqDTO) {
        return R.ok(schedulePlanLogsService.add(addSchedulePlanReqDTO));
    }
}
